//
//  ShoppingCartCountView.m
//  YYBG_IOS
//
//  Created by wyl on 2017/3/9.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "ShoppingCartCountView.h"
#import "BSCommon.h"

@interface ShoppingCartCountView()
    
@property(nonatomic,strong)  UILabel *money ;
@property(nonatomic,strong)  UILabel *chooseCountLabel ;

@property(nonatomic,strong)  UIButton *countBtn ;
@property(nonatomic,strong)  UIButton *checkBtn ;

@end

@implementation ShoppingCartCountView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initCountView];
    }
    return self;
}

-(void)initCountView{
    int allHeight = CGRectGetHeight(self.frame) ;
    int heightCount = allHeight ;//第二个高度
    
    UIView *bottom = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPWIDTH, 1)];
    [self addSubview:bottom];
    bottom.backgroundColor= [UIColor colorWithHexString:COLOR_LIGHT_GRAY];
    
    _checkBtn = [[UIButton alloc]init];
    _checkBtn.width = CGRectGetHeight(self.frame) *2 / 5 ;
    _checkBtn.height = CGRectGetHeight(self.frame) *2 / 5  ;
    _checkBtn.x = 20 ;
    _checkBtn.centerY = CGRectGetHeight(self.frame) / 2  ;
    [_checkBtn setImage:ImageNamed(@"checkbox1") forState:UIControlStateNormal];
    [_checkBtn setImage:ImageNamed(@"checkbox2") forState:UIControlStateSelected];
    [_checkBtn setImage:ImageNamed(@"checkbox2") forState:UIControlStateHighlighted];
    [_checkBtn addTarget:self action:@selector(chooseAll) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_checkBtn];
    
    UILabel *checkAllLabel = [[UILabel alloc]init];
    [checkAllLabel setText:@"全选"];
    checkAllLabel.systemFont = 13 ;
    [checkAllLabel sizeToFit];
    checkAllLabel.x = CGRectGetMaxX(_checkBtn.frame) + 5;
    checkAllLabel.centerY =CGRectGetHeight(self.frame) / 2 ;
    [self addSubview:checkAllLabel];
    
    _chooseCountLabel = [[UILabel alloc]init];
    [_chooseCountLabel setText:@"已选2件"];
    _chooseCountLabel.systemFont = 13 ;
    [_chooseCountLabel sizeToFit];
    _chooseCountLabel.x = checkAllLabel.maxX + 10;
    _chooseCountLabel.centerY =  heightCount / 2 ;
    [self addSubview:_chooseCountLabel];
    
    
    UILabel *heji = [[UILabel alloc]init];
    [heji setText:@"合计 "];
    heji.systemFont = 13 ;
    [heji sizeToFit];
    heji.x = _chooseCountLabel.maxX + 10;
    heji.centerY =  heightCount / 2 ;
    [self addSubview:heji];
    
    _money = [[UILabel alloc]init];
    [_money setText:@""];
    _money.systemFont = 13 ;
    _money.textColor = [UIColor orangeColor];
    _money.width = 80 ;
    _money.height = 30 ;
    _money.x = CGRectGetMaxX(heji.frame)+5;
    _money.centerY =  heightCount / 2 ;
    [self addSubview:_money];
    
    
    _countBtn = [[UIButton alloc]init];
    _countBtn.width = 70 ;
    _countBtn.height = 26 ;
    _countBtn.x = (APPWIDTH - 80) ;
    _countBtn.titleLabel.systemFont = 13 ;
    _countBtn.centerY = heightCount / 2 ;
    [_countBtn setTitle:@"" forState:UIControlStateNormal];
    [_countBtn addTarget:self action:@selector(goPay) forControlEvents:UIControlEventTouchUpInside];
    _countBtn.backgroundColor = [UIColor orangeColor];
    _countBtn.layer.cornerRadius = _countBtn.height / 2;
     [_countBtn setTitle:[NSString stringWithFormat:@"去下单(%d)",10] forState:UIControlStateNormal];
    [self addSubview:_countBtn];
}


-(void)setTotalMoney:(NSInteger)money {
    [_money setText:[NSString stringWithFormat:@"￥%ld",money]];
}
-(void)setTotalGoods:(NSInteger)count {
    [_countBtn setTitle:[NSString stringWithFormat:@"去下单(%ld)",count] forState:UIControlStateNormal];
}

-(void)goPay{
    if (self.delegate) {
        [self.delegate goPayView];
    }
}

-(void)chooseAll{
    
}
@end
